package cn.smbms.tools;

import cn.smbms.pojo.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: smbms02
 * @description:
 * @author: wlg
 * @create: 2021-07-28 15:59:11
 **/
public class MyIntercepter extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User userSession = (User)request.getSession().getAttribute("userSession");
        if(null == userSession){//没有登录或者会话过期
            response.sendRedirect(request.getContextPath());
            return false;
        }
        return true;
    }
}
